<html>
<head><meta charset="utf-8"><title>About SourceAnalyzer · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/About.20SourceAnalyzer.html">About SourceAnalyzer</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="181150966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/About%20SourceAnalyzer/near/181150966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/About.20SourceAnalyzer.html#181150966">(Nov 19 2019 at 20:28)</a>:</h4>
<p>The <code>SourceAnalyzer </code> constructor :</p>
<div class="codehilite"><pre><span></span><span class="k">impl</span><span class="w"> </span><span class="n">SourceAnalyzer</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="w"></span>
<span class="w">        </span><span class="n">db</span>: <span class="kp">&amp;</span><span class="nc">impl</span><span class="w"> </span><span class="n">HirDatabase</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">node</span>: <span class="nc">Source</span><span class="o">&lt;&amp;</span><span class="n">SyntaxNode</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">offset</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">TextUnit</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">SourceAnalyzer</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</pre></div>


<p><span class="user-mention" data-user-id="133169">@matklad</span> What <code>node</code> can I put in ? Can I put in a <code>Source(HirFileId::MacroFile, ast)</code>? If so, how  <code>SourceAnalyzer::expand</code> resolve other macro call?</p>



<a name="181151129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/About%20SourceAnalyzer/near/181151129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/About.20SourceAnalyzer.html#181151129">(Nov 19 2019 at 20:31)</a>:</h4>
<p>And must <code>Source::ast</code> is inside <code>Source::file_id</code> ?</p>



<a name="181151379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/About%20SourceAnalyzer/near/181151379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/About.20SourceAnalyzer.html#181151379">(Nov 19 2019 at 20:34)</a>:</h4>
<p><span class="user-mention" data-user-id="216201">@Edwin Cheng</span> in theory you should be able to use just about any syntax node as <code>node: Source&lt;SyntxNOde&gt;</code>, as long as you use the ast is contained in <code>db.parse_or_expand(node.file_id)</code>. However, the resolver for macro files will indeed be wrong, this needs to be fixed somehow inside the SourceAnalyzer itself</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>